<template>
    <el-dialog :visible.sync="open" @close="close" :title="title" width="800px" append-to-body destory-on-close>
        <el-form ref="elForm" :model="formData" size="small" label-width="100px" label-position="left">
            <el-row :gutter="15">
                <el-col :span="24">
                    <el-form-item label="执行人" prop="dept">
                        <span :style="{ marginRight: '15px' }" v-if="formData.receiveUser != null">{{ formData.receiveUserName }}</span>
                        <el-button type="primary" size="mini" @click="handlePickRole">选择执行人</el-button>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15">
                <el-col :span="24">
                    <el-form-item label="任务内容" prop="location">
                        <el-input type="textarea" v-model="formData.taskContent" placeholder="请输入任务内容" :style="{ width: '100%' }" :rows="5"> </el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15">
                <el-col :span="24">
                    <el-form-item label="辅助信息" prop="location">
                        <el-input type="textarea" v-model="formData.helpContent" placeholder="请输入辅助信息" :style="{ width: '100%' }" :rows="5"> </el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <div slot="footer">
            <el-button @click="close">取消</el-button>
            <el-button type="primary" @click="handleConfirm">确定</el-button>
        </div>
        <staff-choose-dialog ref="staffChoose" :muilt="false" @Unitpersonnel="onStaffChoose" />
    </el-dialog>
</template>
<script>
import dialogMixin from "@/mixins/dialogMixin";
import StaffChooseDialog from "@/views/components/staffChooseDialog/index";
import Uploader from "@/views/components/uploader/index.vue";
import uploAding from "@/views/components/uploAding/index.vue";

export default {
    name: "TaskEditDialog",
    mixins: [dialogMixin],
    components: { StaffChooseDialog, Uploader, uploAding },
    props: {
        taskType: {
            type: String,
            default: "drill",
        },
    },
    data() {
        return {
            formData: {
                userId: 0,
                groupId: 0,
                taskContent: "",
                helpContent: "",
                sort: 0,
            },
            userName: "",
            title: "",
            messageId: 0,
            messageContent: "",
        };
    },
    computed: {},
    watch: {},
    created() {},
    mounted() {},
    methods: {
        add() {
            this.formData = {
                id: 0,
                receiveUser: null,
                receiveUserName: "",
                taskDept: null,
                taskDeptName: "",
                taskContent: "",
                helpContent: "",
            };
            this.userName = "";
            this.messageId = 0;
            this.messageContent = "";
            this.title = "新增处置任务";
            this.open = true;
        },
        addChildTask() {
            this.formData = {
                id: 0,
                receiveUser: null,
                receiveUserName: "",
                taskDept: null,
                taskDeptName: "",
                taskContent: "",
                helpContent: "",
            };
            this.userName = this.formData.receiveUserName;
            this.title = "新增处置任务";
            this.open = true;
        },
        edit(data) {
            this.handleId = data.handleId;
            this.formData = {
                id: data.id,
                receiveUser: data.receiveUser,
                receiveUserName: data.receiveUserName,
                taskDept: data.taskDept,
                taskDeptName: data.taskDeptName,
                taskContent: data.taskContent,
                helpContent: data.helpContent,
            };
            this.userName = data.userName;
            this.title = "修改处置任务";
            this.open = true;
        },
        handleConfirm() {
            if (this.formData.taskContent == "") {
                this.$modal.msgError("请填写任务内容");
                return false;
            }
            if (this.formData.userId == 0) {
                this.$modal.msgError("请选择执行人");
                return false;
            }
            this.$emit("handleOk", this.formData);
        },
        handlePickRole() {
            this.$refs.staffChoose.showDialog("选择任务执行人");
        },
        onRoleSelected(data) {
            this.formData.userId = data.roleId;
            this.formData.groupId = data.groupId;
            this.userName = data.roleName;
        },
        onStaffChoose(deptId, userId, user, dept) {
            this.formData.receiveUser = userId;
            this.formData.taskDept = deptId;
            this.formData.receiveUserName = user.userName;
            this.formData.taskDeptName = dept.name;
            this.userName = user.userName;
        },
    },
};
</script>
<style></style>
